﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.ComponentModel;
using System.Windows.Media;

namespace WPF.CustomControl
{

    [TemplatePart(Name = "winProgressBar", Type = typeof(HLProgressBar))]
    public class HLUserControlExt : UserControl
    {


        private HLProgressBar _winProgressBar;

        public HLUserControlExt()
            : base()
        {
            ResourceDictionary rd = Application.LoadComponent(new Uri("/WPF.CustomControl;Component/Resources/ResUserControl.xaml", UriKind.Relative)) as ResourceDictionary;
            Style s = rd["cusWin"] as Style;
            Style = s;
            Unloaded += new RoutedEventHandler(HLUserControl_Unloaded);
            FontFamily = new FontFamily("宋体");
            FontSize = 12;
        }

        void HLUserControl_Unloaded(object sender, RoutedEventArgs e)
        {
            StopProgress();
        }
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();
            _winProgressBar = Template.FindName("winProgressBar", this) as HLProgressBar;
        }
        /// <summary>
        /// 启动进度条。
        /// </summary>
        public void StartProgress()
        {
            if (_winProgressBar != null)
            {
                //_winProgressBar.SmallCircularBrush = ControlStyle.ToolBarSelectedItemBackground;
                _winProgressBar.Start();
            }
        }

        /// <summary>
        /// 停止进度条。
        /// </summary>
        public void StopProgress()
        {
            if (_winProgressBar != null)
            {
                _winProgressBar.Stop();
                _winProgressBar.tb_Text.Text = "";
                Grid.SetZIndex(_winProgressBar.tb_Text, -1);
            }
        }

    }
}
